<?php
include("../lib/functions.php");
noCache();
session_start();
$mat_id = $_GET['mat_id'];
?>
<?php require_once('../../include/defaults.php'); ?>
<?php require_once("../../include/language.php");?>
<?php require_once('../../Connections/cotiza.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_cotiza, $cotiza);
$query_items = "SELECT pt_id, REPLACE(REPLACE(pt_desc,'LLDPE ',''),'LDPE ','') as pt_desc FROM pt_mstr WHERE pt_pm_code = 'p' ORDER BY pt_desc";
$items = mysql_query($query_items, $cotiza) or die(mysql_error());
$row_items = mysql_fetch_assoc($items);
$totalRows_items = mysql_num_rows($items);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>Documento sin t&iacute;tulo</title>
<link href="../../main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../lib/funciones.js"></script>
<script language="javascript" type="text/javascript">

var indiceFilaFormulario=1;

function addItem(){
 var itemId   = document.getElementById("item").value;
 var indice   = document.getElementById("item").selectedIndex;
 var itemDesc = document.getElementById("item").options[indice].text;
 var remove   = '<a href="javascript:removeItem(this)"><img src="../img/cancel.png" width="16" height="16" border="0" /></a>';
 var hidden   = '<input type="hidden" name="materiales[' + indiceFilaFormulario + ']" id="materiales" value="' + itemId + '" />';
  
 myNewRow = document.getElementById("items").insertRow(-1);
 myNewRow.id=indiceFilaFormulario;
 myNewCell=myNewRow.insertCell(-1);
 myNewCell.innerHTML=itemDesc + hidden;
 myNewCell=myNewRow.insertCell(-1);
 myNewCell.innerHTML=remove;
 myNewCell=myNewRow.insertCell(-1);
 indiceFilaFormulario++;
}
 
function removeItem(obj){
 var oTr = obj;
 while(oTr.nodeName.toLowerCase()!='tr'){
  oTr=oTr.parentNode;
 }
 var root = oTr.parentNode;
 root.removeChild(oTr);
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="mntomateriales_detalle.php?mat_id=<?php echo $mat_id;?>" target="detalle_materiales">
  <strong>Item (Fantasma)</strong>
  <table border="0" id="items">
    <tr>
      <td width="38">
      <select name="item" class="default" id="item">
        <?php
do {  
?>
        <option value="<?php echo $row_items['pt_id']?>"><?php echo $row_items['pt_desc']?></option>
        <?php
} while ($row_items = mysql_fetch_assoc($items));
  $rows = mysql_num_rows($items);
  if($rows > 0) {
      mysql_data_seek($items, 0);
	  $row_items = mysql_fetch_assoc($items);
  }
?>
      </select></td>
      <td width="16"><a href="javascript:addItem()"><img src="../img/plus.png" width="16" height="16" border="0" /></a></td>
      <td width="21"><input type="submit" name="button3" id="button3" value="Formular" /></td>
    </tr>
  </table>
</form>

<table border="0" align="center">
  <tr>
    <td><iframe src="mntomateriales_detalle.php?acc=build&mat_id=<?php echo $mat_id;?>" name="detalle_materiales" width="600" height="300" frameborder="0"></iframe></td>
  </tr>
</table>
<table width="479" border="0">
    <tr>
      <td width="272" align="left" class="descripcion_alpie" ><?php if($acc == "edit" and $totalRows == 0)echo $text_newreg; elseif($acc == "edit" and $totalRows == 1)echo $text_editreg;?></td>
      <td width="86" align="right"><?php if ($id_usuario == ""){?>
        <input name="button" type="button" onclick="window.open('mntomateriales.php?acc=edit','_self');" class="default" id="button" value="Editar" />
        <?php }?></td>
      <td width="46" align="right"><input name="button2" type="button" onclick="window.open('mntomateriales.php?acc=edit&cod_material=<?php echo $mat_id; ?>','_self');" class="default" id="button2" value="Volver" /></td>
      <td width="57" align="right"><input name="Submit" type="button" class="default" value="Siguiente" onclick="" /></td>
    </tr>
</table>
</body>
</html>
<?php
mysql_free_result($items);
?>
<?php 
mysql_close($cotiza);
?>